Format()

String Function

Syntax samples

FORMAT(<expression>, <total number of characters in expression> {,<digits after decimal>})

DISPLAY "The value of Var1 is" $ FORMAT(Var1, 5)

Description

Converts a number to a string in the format specified. FORMAT() should most often be used with the concatenation operator ("$") and another string, as in the syntax example above. Format is often used in conjunction with the XWRITE statement to produce formatted output.

Valid In

Any string expression.

Components

<expression>

This expression will be evaluated and converted to a string. If the expression results in an integer, it will be converted to a real.

<total number of characters in expression>

This expression formats the number so that it occupies a total space equal to the number of digits before + number of digits after the decimal + one character for the decimal point. For example if you were to do the following logic: XWRITE file1 Format (10.0 4 1) XWRITE file1 Format (1.0 4 1), it will show up in the file as 10.0 1.0 with a space before the 1.0.

<digits after decimal>

An expression that evaluates to the maximum number of digits to the right of the decimal. If there are more digits to the right of the decimal than this number, the excess digits will be truncated. If there are fewer digits, ProModel will pad the number with zeros.

Example

The logic below writes formatted output to a file with XWRITE and FORMAT.

XWRITE File1, "The variable Var1 is" $ FORMAT(Var1,5,2)

In this example, if the value of Var1 is 378.87654, it would be written to the file as:

The variable Var1 is 378.87

(Two spaces)

See Also

WRITE and WRITELINE.